package xyz.zq.cloud.common.security.service;

import lombok.Getter;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;

/**
 * 扩展用户信息
 *
 * @author hzq
 * @date 2020/4/28 21:21
 */
public class CloudUser extends User {

    /**
     * 用户ID
     */
    @Getter
    private Integer id;
    /**
     * 部门ID
     */
    @Getter
    private Integer deptId;
    /**
     * 租户ID
     */
    @Getter
    private Integer companyId;

    /**
     * Construct the <code>User</code> with the details required by
     * {@link DaoAuthenticationProvider}.
     *
     * @param id                    用户ID
     * @param deptId                部门ID
     * @param username              提供给的用户名
     *                              <code>DaoAuthenticationProvider</code>
     * @param password              应当提供给密码的密码
     *                              <code>DaoAuthenticationProvider</code>
     * @param enabled               设置 <code>true</code> 如果启用了用户
     * @param accountNonExpired     设置 <code>true</code> 如果帐户尚未过期
     * @param credentialsNonExpired 设置 <code>true</code> 如果凭据还没有过期
     * @param accountNonLocked      设置 <code>true</code> 如果帐户未锁定
     * @param authorities           授予呼叫者的权限，如果他们提供了正确的用户名和密码，并启用了该用户。不为空
     * @throws IllegalArgumentException 如果一个 <code>null</code> 值以参数或元素形式传递
     *                                  <code>GrantedAuthority</code> collection
     */
    public CloudUser(Integer id,
                     Integer deptId,
                     Integer companyId,
                     String username,
                     String password,
                     boolean enabled,
                     boolean accountNonExpired,
                     boolean credentialsNonExpired,
                     boolean accountNonLocked,
                     Collection<? extends GrantedAuthority> authorities) {
        super(username, password, enabled, accountNonExpired,
                credentialsNonExpired, accountNonLocked, authorities);
        this.id = id;
        this.deptId = deptId;
        this.companyId = companyId;
    }

}
